package com.luo.config;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyPicConfig implements WebMvcConfigurer {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        /*System.out.println("配置文件已经生效");*/
//        registry.addResourceHandler("/imgs/**").addResourceLocations("file:E:\\project\\project_code\\luoqianyi_blog\\blog-java\\src\\main\\resources\\static\\imgs\\");
//        registry.addResourceHandler("/pictures/**").addResourceLocations("file:E:\\project\\project_code\\luoqianyi_blog\\blog-java\\src\\main\\resources\\static\\pictures\\");
        String os = System.getProperty("os.name");
        if (os.toLowerCase().startsWith("win")) {  //如果是Windows系统
            registry.addResourceHandler("/imgs/**")
                    .addResourceLocations("file:E:\\project\\project_code\\luoqianyi_blog\\blog-java\\src\\main\\resources\\static\\imgs\\");
            registry.addResourceHandler("/pictures/**").
                    addResourceLocations("file:E:\\project\\project_code\\luoqianyi_blog\\blog-java\\src\\main\\resources\\static\\pictures\\");
        } else {  //linux 和mac
            registry.addResourceHandler("/imgs/**")
                    .addResourceLocations("file:/project/blog-java/src/main/resources/static/imgs/");
            registry.addResourceHandler("/pictures/**")
                    .addResourceLocations("file:/project/blog-java/src/main/resources/static/pictures/");

        }

    }
}
